package com.letv.android.client.view;

import android.content.Context;
import android.graphics.drawable.AnimationDrawable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.letv.android.young.client.R;
import com.letv.core.bean.TipMapBean.TipBean;
import com.letv.core.constant.LetvConstant.DialogMsgConstantId;
import com.letv.core.constant.PlayConstant.PlayErrCode;
import com.letv.core.utils.LogInfo;
import com.letv.core.utils.StatisticsUtils;
import com.letv.core.utils.TipUtils;
import com.letv.core.utils.UIsUtils;
import com.letv.datastatistics.util.PageIdConstant;
import com.ledim.utils.ToastUtil;

public class PlayLoadLayout extends FrameLayout implements OnClickListener {

    public static boolean mIsShowBlock = true;

    private int errState = 0;

    private ImageView loading;

    /**
     * 没有视频
     */
    private View not_play;

    /**
     * 请求错误提示
     */
    private View request_error;
    private TextView request_error_text;

    /**
     * 请求错误提示点击
     */
    private View request_error_btn;

    /**
     * 播放失败
     */
    private View cannot_play;

    /**
     * 播放失败提示点击
     */
    private View cannot_play_btn;

    /**
     * vip付费提示
     */
    private View vip_not_login_error;

    /**
     * vip付费提示
     */
    private View vip_login_error;

    /**
     * 无版权外跳提示
     */
    private View jump_error;

    /**
     * ip海外版权提示
     */
    private View ip_error;

    private TextView ip_error_text;

    private TextView ip_error_call_text;

    /**
     * 点播片提示
     */
    private View demand_error;

    /**
     * 本地播放异常
     */
    private View local_error;

    /**
     * vip付费提示按钮
     */
    private View vip_not_login_error_btn;

    /**
     * vip付费提示按钮
     */
    private View vip_login_error_btn;

    private TextView jump_error_text;
    /**
     * 无版权外跳提示按钮
     */
    private TextView jump_error_btn;
    /**
     * 
     */
    private TextView jump_error_button_disable;

    /**
     * 点播片提示按钮
     */
    private View demand_error_btn;

    /**
     * 视频加载提示文字
     */
    private TextView loadingTxt;

    /**
     * 提交反馈按钮
     */
    private TextView mTxtSubmitInfo;
    private PlayLoadLayoutCallBack callBack;

    private TextView dlnaTitle;
    private View dlnaClose;
    private boolean isDlnaState;

    private LoadingCallBack mLoadingCallBack;

    private Context mContext;

    private AnimationDrawable animationDrawable = null;

    public PlayLoadLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    public PlayLoadLayout(Context context) {
        super(context);
        init(context);
    }

    private void init(Context context) {
        mContext = context;
        inflate(context, R.layout.letv_play_loading_layout, this);
        findView();
    }

    public int getErrState() {
        return errState;
    }

    public void setErrState(int errState) {
        this.errState = errState;
    }

    private void findView() {
        loading = (ImageView) findViewById(R.id.loading);
        not_play = findViewById(R.id.no_play_error);
        request_error = findViewById(R.id.request_error);
        request_error_text = (TextView) findViewById(R.id.request_error_text);
        request_error_btn = findViewById(R.id.request_error_btn);

        cannot_play = findViewById(R.id.cannot_play);
        cannot_play_btn = findViewById(R.id.cannot_play_btn);

        vip_not_login_error = findViewById(R.id.vip_not_login_error);
        vip_login_error = findViewById(R.id.vip_login_error);
        jump_error = findViewById(R.id.jump_error);
        ip_error = findViewById(R.id.ip_error);
        ip_error_text = (TextView) findViewById(R.id.ip_error_text);
        ip_error_call_text = (TextView) findViewById(R.id.ip_error_call_text);
        vip_not_login_error_btn = findViewById(R.id.vip_not_login_error_button);
        vip_login_error_btn = findViewById(R.id.vip_login_error_button);
        jump_error_text = (TextView) findViewById(R.id.jump_error_text);
        jump_error_btn = (TextView) findViewById(R.id.jump_error_button);
        jump_error_button_disable = (TextView) findViewById(R.id.jump_error_button_disable);
        demand_error = findViewById(R.id.demand_error);
        demand_error_btn = findViewById(R.id.demand_error_button);
        local_error = findViewById(R.id.local_error_view);
        loadingTxt = (TextView) findViewById(R.id.loadingTxt);
        mTxtSubmitInfo = (TextView) findViewById(R.id.txt_commit_info);
        mTxtSubmitInfo.setOnClickListener(this);
        request_error_btn.setOnClickListener(this);
        cannot_play_btn.setOnClickListener(this);
        vip_not_login_error_btn.setOnClickListener(this);
        vip_login_error_btn.setOnClickListener(this);
        jump_error_btn.setOnClickListener(this);
        demand_error_btn.setOnClickListener(this);
        ip_error_call_text.setOnClickListener(this);

        loading.setImageResource(R.anim.video_loading_animation);
        animationDrawable = (AnimationDrawable)loading.getDrawable();
        animationDrawable.setOneShot(false);
        animationDrawable.start();

        resizeLoadingText(false);// 初始化竖屏

        dlnaTitle = (TextView) findViewById(R.id.dlna_title);
        dlnaClose = findViewById(R.id.dlna_close);
        dlnaClose.setOnClickListener(this);
    }

    // public void setLoadingTxt(int resId){
    // if(loadingTxt.getVisibility() == View.GONE){
    // loadingTxt.setVisibility(VISIBLE);
    // }
    // loadingTxt.setText(resId);
    // }
    // public void setLoadingTxt(String text){
    // if(loadingTxt.getVisibility() == View.GONE){
    // loadingTxt.setVisibility(VISIBLE);
    // }
    // loadingTxt.setText(text);
    // }

    public void loading() {
        loading(false);
    }

    /**
     * 视频加载progress---数据加载中...
     * 
     * @param showText
     * 是否显示文字
     */
    public void loading(boolean showText) {
        if (!isDlnaState) {
            LogInfo.log("wuxinrong", "显示圈圈...");
            loading.setVisibility(VISIBLE);
            if (showText) {
                LogInfo.log("wuxinrong", "显示 >>> 正在加载，请稍候...");
                loadingTxt.setText("不要放弃啊！");
                loadingTxt.setVisibility(VISIBLE);
            } else {
                loadingTxt.setVisibility(GONE);
            }
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
            if (mLoadingCallBack != null && mIsShowBlock) {
                mLoadingCallBack.loading(true);
            }
        }
    }

    public interface LoadingCallBack {
        void loading(boolean show);
    }

    public void setLoadingCallBack(LoadingCallBack loadingCallBack) {
        mLoadingCallBack = loadingCallBack;
    }

    /**
     * 视频加载progress---即将播放...
     * 
     * @param videoName
     */
    public void loadingVideo(String videoName) {
        if (!isDlnaState) {
            loading.setVisibility(VISIBLE);
            loadingTxt.setVisibility(VISIBLE);
            if (!TextUtils.isEmpty(videoName)) {
                String willPlay = getContext().getString(R.string.will_play);
                LogInfo.log("wuxinrong", "显示 >>> 即将播放");
                loadingTxt.setText("不要放弃啊！");
            } else {
                LogInfo.log("wuxinrong", "显示 >>> 正在加载，请稍候...");
                loadingTxt.setText("不要放弃啊！");
//                loading.setVisibility(GONE);
//                loadingTxt.setText("没有正在播放的影片");
            }
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }

    }

    public void noLiveVideo() {
        if (!isDlnaState) {
            loading.setVisibility(GONE);
            loadingTxt.setVisibility(VISIBLE);
            loadingTxt.setText("没有正在播放的影片");

            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void loadingStart(String loadingMsg, String videoName) {
        if (!isDlnaState) {
            loading.setVisibility(VISIBLE);
            loadingTxt.setVisibility(VISIBLE);
            if (!TextUtils.isEmpty(loadingMsg)) {
                loadingTxt.setText("不要放弃啊！");
            } else if (!TextUtils.isEmpty(videoName)) {
                String willPlay = getContext().getString(R.string.will_play);
                loadingTxt.setText("不要放弃啊！");
            } else {
                loadingTxt.setText("不要放弃啊！");
            }
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    /**
     * 重新layout loadingTxt在横屏和竖屏下的宽度=当前屏幕的宽度*0.6
     * 
     * @param isLandscape
     */
    public void resizeLoadingText(boolean isLandscape) {
        RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) loadingTxt.getLayoutParams();
        params.width = (int) (UIsUtils.getScreenWidth(mContext) * 0.6f);
        loadingTxt.requestLayout();
    }

    /**
     * 是否有异常提示
     * 
     * @return
     */
    public boolean isErrorTagShow() {
        return request_error.getVisibility() == View.VISIBLE || not_play.getVisibility() == View.VISIBLE
                || cannot_play.getVisibility() == View.VISIBLE || vip_not_login_error.getVisibility() == View.VISIBLE
                || vip_login_error.getVisibility() == View.VISIBLE || jump_error.getVisibility() == View.VISIBLE
                || ip_error.getVisibility() == View.VISIBLE || demand_error.getVisibility() == View.VISIBLE
                || local_error.getVisibility() == View.VISIBLE;
    }

    public void finish() {
        if (null != callBack) {
            callBack.calledInFinish();
        }
        errState = 0;
        loading.setVisibility(View.GONE);
        loadingTxt.setVisibility(View.GONE);
        not_play.setVisibility(GONE);
        request_error.setVisibility(GONE);
        mTxtSubmitInfo.setVisibility(GONE);
        cannot_play.setVisibility(GONE);
        vip_not_login_error.setVisibility(GONE);
        vip_login_error.setVisibility(GONE);
        jump_error.setVisibility(GONE);
        ip_error.setVisibility(GONE);
        demand_error.setVisibility(GONE);
        local_error.setVisibility(GONE);
        if (mLoadingCallBack != null) {
            mLoadingCallBack.loading(false);
        }
        UIsUtils.enableScreenAlwaysOn(getContext());
    }

    public boolean isLoadingShow() {
        return loading.getVisibility() == View.VISIBLE || request_error.getVisibility() == View.VISIBLE;
    }

    public void notPlay() {
        if (!isDlnaState) {
            errState = 1;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(VISIBLE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void requestError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 2;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(VISIBLE);
            mTxtSubmitInfo.setVisibility(View.GONE);
            TipBean dialogMsgByMsg = TipUtils.getTipBean(mContext,"100075");
            if (dialogMsgByMsg != null && !TextUtils.isEmpty(dialogMsgByMsg.getMessage())) {
                request_error_text.setText(dialogMsgByMsg.getMessage());
            }

            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
        UIsUtils.disableScreenAlwaysOn(getContext());
    }

    public void requestError(String msg, String errorCode) {
        requestError(msg);
        // 此类错误代码 添加提交反馈提示
        boolean show = TextUtils.equals(PlayErrCode.OVERSEA_IP_LIMITED_HONGKONG, errorCode)
                || TextUtils.equals(PlayErrCode.OVERSEA_IP_LIMITED_NO_CHINA, errorCode)
                || TextUtils.equals(PlayErrCode.ADDRESS_OR_DATA_ACQUIRED_FAILED, errorCode)
                || TextUtils.equals(PlayErrCode.PARAMS_ERROR, errorCode)
                || TextUtils.equals(PlayErrCode.VIDEO_INFO_IS_NULL, errorCode)
                || TextUtils.equals(PlayErrCode.DOWNLOAD_VIDEO_FILE_FAILED, errorCode)
                || TextUtils.equals(PlayErrCode.CURRENT_CODE_STREAM_COULD_NOT_PLAY_CORRECT, errorCode)
                || TextUtils.equals(PlayErrCode.LOCAL_VIDEO_FILE_PLAY_FAILED, errorCode);

        mTxtSubmitInfo.setVisibility(show ? View.VISIBLE : View.GONE);
    }

    public void requestError(String msg) {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 2;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(VISIBLE);
            mTxtSubmitInfo.setVisibility(View.GONE);
            if (!TextUtils.isEmpty(msg)) {
                request_error_text.setText(msg);
            } else {
                TipBean dialogMsgByMsg = TipUtils.getTipBean(mContext,"100075");
                if (dialogMsgByMsg != null && !TextUtils.isEmpty(dialogMsgByMsg.getMessage())) {
                    request_error_text.setText(dialogMsgByMsg.getMessage());
                }
            }

            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
        UIsUtils.disableScreenAlwaysOn(getContext());
    }

    public void openDlnaController(String msg) {
        isDlnaState = true;
        loading.setVisibility(View.GONE);
        loadingTxt.setVisibility(View.GONE);
        not_play.setVisibility(GONE);
        cannot_play.setVisibility(GONE);
        vip_not_login_error.setVisibility(GONE);
        vip_login_error.setVisibility(GONE);
        jump_error.setVisibility(GONE);
        ip_error.setVisibility(GONE);
        demand_error.setVisibility(GONE);
        local_error.setVisibility(GONE);
        request_error.setVisibility(GONE);
        mTxtSubmitInfo.setVisibility(GONE);
        dlnaTitle.setText(msg);
    }

    public void cannotPlayError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 2;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            cannot_play.setVisibility(VISIBLE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void vipNotLoginError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(VISIBLE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void vipLoginError() {
        if (null != callBack) {
            callBack.calledInError();
        }
        errState = 4;
        loading.setVisibility(View.GONE);
        loadingTxt.setVisibility(View.GONE);
        not_play.setVisibility(GONE);
        request_error.setVisibility(GONE);
        mTxtSubmitInfo.setVisibility(GONE);
        cannot_play.setVisibility(GONE);
        vip_not_login_error.setVisibility(GONE);
        vip_login_error.setVisibility(VISIBLE);
        jump_error.setVisibility(GONE);
        ip_error.setVisibility(GONE);
        demand_error.setVisibility(GONE);
        local_error.setVisibility(GONE);
    }

    public void demandError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 5;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(VISIBLE);
            local_error.setVisibility(GONE);
        }
    }

    public void jumpError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 6;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(VISIBLE);
            jump_error_text.setText(TipUtils.getTipMessage(mContext,"100051", R.string.dialog_jump_error_title));
            jump_error_button_disable.setVisibility(View.GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    /**
     * 版权错误
     * 
     * @param value 1:显示可跳转按钮;2:显示文案，不可;3:不显示按钮或者文案
     */
    public void jumpError(int value) {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 6;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(VISIBLE);
            errorExposure();
            jump_error_text.setText(TipUtils.getTipMessage(mContext,"100051", R.string.dialog_jump_error_title));
            if (value == 1) {
                jump_error_btn.setVisibility(View.GONE);
                jump_error_button_disable.setVisibility(View.GONE);
            } else if (value == 2) {
                jump_error_btn.setVisibility(View.GONE);
                jump_error_button_disable.setText(TipUtils.getTipMessage(mContext,"100056", R.string.dialog_jump_error_web));
                jump_error_button_disable.setVisibility(View.VISIBLE);
            } else {
                jump_error_btn.setVisibility(View.GONE);
                jump_error_button_disable.setVisibility(View.GONE);
            }
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void jumpError(String title, String msg, boolean showBtn) {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 6;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(VISIBLE);
            errorExposure();
            if (!TextUtils.isEmpty(title)) {
                jump_error_text.setText(title);
            } else {
                jump_error_text.setText(TipUtils.getTipMessage(mContext,"100051", R.string.dialog_jump_error_title));
            }
            if (showBtn) {
                jump_error_btn.setVisibility(View.VISIBLE);
                jump_error_button_disable.setVisibility(View.GONE);
                if (!TextUtils.isEmpty(msg)) {
                    jump_error_btn.setText(msg);
                }
            } else {
                jump_error_btn.setVisibility(View.GONE);
                jump_error_button_disable.setVisibility(View.VISIBLE);
                if (!TextUtils.isEmpty(msg)) {
                    jump_error_button_disable.setText(msg);
                }
            }
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    private void errorExposure() {
        if (jump_error.getVisibility() == View.VISIBLE) {
            String pageid;
            if (UIsUtils.isLandscape(mContext)) { // 全屏
                pageid = PageIdConstant.fullPlayPage;
            } else {
                pageid = PageIdConstant.halpPlayPage;
            }
            StatisticsUtils.staticticsInfoPost(mContext, "19", "c76", null, -1, null, pageid, "-", "-", "-", "-", "-");
        }
    }

    public void ipError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 7;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(VISIBLE);
            // ip_error_text.setText(R.string.no_play_only_china);
            ip_error_text.setText(TipUtils.getTipMessage(mContext,DialogMsgConstantId.NO_PLAY_ONLY_CHINA,
                    R.string.no_play_only_china));
            ip_error_call_text.setVisibility(View.VISIBLE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void ipError(String msg) {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 7;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(VISIBLE);
            msg = msg.replace("#", "\n");
            ip_error_text.setText(msg);
            ip_error_call_text.setVisibility(View.GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void ipError(String msgTip, boolean isHk) {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 7;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(VISIBLE);
            ip_error_call_text.setVisibility(View.VISIBLE);
            if (!TextUtils.isEmpty(msgTip)) {
                ip_error_text.setText(msgTip);
            } else {
                ip_error_text.setText(R.string.no_play_only_china);
            }
            demand_error.setVisibility(GONE);
            local_error.setVisibility(GONE);
        }
    }

    public void localError() {
        if (!isDlnaState) {
            if (null != callBack) {
                callBack.calledInError();
            }
            errState = 8;
            loading.setVisibility(View.GONE);
            loadingTxt.setVisibility(View.GONE);
            not_play.setVisibility(GONE);
            request_error.setVisibility(GONE);
            mTxtSubmitInfo.setVisibility(GONE);
            cannot_play.setVisibility(GONE);
            vip_not_login_error.setVisibility(GONE);
            vip_login_error.setVisibility(GONE);
            jump_error.setVisibility(GONE);
            ip_error.setVisibility(GONE);
            demand_error.setVisibility(GONE);
            local_error.setVisibility(VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        if (request_error_btn == v) {
            if (callBack != null)
                callBack.onRequestErr();
            errState = 0;
        } else if (vip_not_login_error_btn == v) {
            if (callBack != null)
                callBack.onVipErr(false);
            errState = 0;
        } else if (vip_login_error_btn == v) {
            if (callBack != null)
                callBack.onVipErr(true);
            errState = 0;
        } else if (jump_error_btn == v) {
            if (callBack != null)
                callBack.onJumpErr();
            errState = 0;
            errorClick();
        } else if (demand_error_btn == v) {
            if (callBack != null)
                callBack.onDemandErr();
            errState = 0;
        } else if (cannot_play_btn == v) {
            if (null != callBack) {
                callBack.onPlayFailed();
            }
            errState = 0;
        } else if (dlnaClose == v) {
            isDlnaState = false;
            if (null != callBack) {
                callBack.closeDlna(true);
            }
        } else if (mTxtSubmitInfo == v || ip_error_call_text == v) {
            if (null != callBack) {
                callBack.commitErrorInfo();
            }
            // 提交反馈统计--5.7
            if (UIsUtils.isLandscape(mContext)) {// 全屏
                StatisticsUtils.staticticsInfoPost(mContext, "0", "c65", null, 5, null, PageIdConstant.fullPlayPage,
                        null, null, null, null, null);
            } else {// 半屏
                StatisticsUtils.staticticsInfoPost(mContext, "0", "c65", null, 5, null, PageIdConstant.halpPlayPage,
                        null, null, null, null, null);
            }
            // UIsPlayerLibs.showToast("            提交成功\n我们已经骑快马去处理了");
            // ToastUtils.showCentorTextToast(mContext, "提交成功\n我们已经骑快马去处理了");
            ToastUtil.toast("提交成功\n我们已经骑快马去处理了");
            // UIsPlayerLibs.showToast(LetvToolsPlayerLibs.getTextFromServer("100008",
            // playAlbumController.getActivity().getString(R.string.complaintSuccess)));
        }
    }

    private void errorClick() {
        String pageid;
        if (UIsUtils.isLandscape(mContext)) { // 全屏
            pageid = PageIdConstant.fullPlayPage;
        } else {
            pageid = PageIdConstant.halpPlayPage;
        }
        StatisticsUtils.staticticsInfoPost(mContext, "0", "c76", null, 1, null, pageid, "-", "-", "-", "-", "-");
    }

    public PlayLoadLayoutCallBack getCallBack() {
        return callBack;
    }

    public void setCallBack(PlayLoadLayoutCallBack callBack) {
        this.callBack = callBack;
    }

    /**
     * 点击回调
     */
    public interface PlayLoadLayoutCallBack {
        void onRequestErr();

        void onVipErr(boolean isLogin);

        void onJumpErr();

        void onDemandErr();

        void onPlayFailed();

        void calledInError();

        void calledInFinish();

        void closeDlna(boolean isStopDlnaPlay);

        void commitErrorInfo();
        /**
         * 提交反馈信息
         * 
         * @author yangn
         */
        // void commitErrorInfo(View sender);
    }

    public boolean isShowLoading() {
        return loading.getVisibility() == View.VISIBLE;
    }

    public String getJumpBtnText() {
        if (jump_error_btn.getVisibility() == VISIBLE) {
            return jump_error_btn.getText().toString();
        }

        return "";
    }
}
